/*
  Copyright 1996-2003
  Simon Whiteside

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  $Id: TreeNodeIterator.java,v 1.4 2003/02/24 18:10:53 simkin_cvs Exp $
*/

package simkin;
import java.util.*;

/**
 * This class provides a means of iterating over the children of a TreeNode
 */
final public class TreeNodeIterator  {
    TreeNode m_Node;
    int m_Index;
    /**
     * Constructor - is passed a TreeNode whose children will be iterated
     */
    public TreeNodeIterator(TreeNode node){
	m_Node=node;
	m_Index=0;
    }
    /**
     * This function returns true if the iteration has not yet been finished
     */
    public boolean hasMoreElements(){
	return m_Index<m_Node.numChildren();
    }
    /**
     * this function returns the next element in the iteration
     * @exception NoSuchElementException - this is thrown if the function is called after the iteration has finished
     */
    public TreeNode nextElement() throws NoSuchElementException{
	TreeNode elt=null;
	if (m_Index<m_Node.numChildren()){
	    elt=m_Node.nthChild(m_Index);
	    m_Index++;
	}else
	    throw new NoSuchElementException();
	return elt;
    }
}
